### 面的内外环线 https://blog.csdn.net/Mechanicoder/article/details/127477160


from OCC.Extend.DataExchange import read_iges_file
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_FACE, TopAbs_WIRE
from OCC.Core.TopoDS import topods
from OCC.Core.BRepAdaptor import BRepAdaptor_Surface
from OCC.Display.SimpleGui import init_display
from OCC.Core.ShapeAnalysis import shapeanalysis_OuterWire
from OCC.Display.OCCViewer import rgb_color

# 加载零件模型文件
part = read_iges_file("assets/recognize/0109.IGS")  # 替换为你的零件模型文件路径

# 初始化3D视图
display, start_display, _, _ = init_display()

# 设置颜色
highlight_color = (0.0, 0.0, 1.0)  # 蓝色

# 提取内部为空的平面的内部边界线
face_explorer = TopExp_Explorer(part, TopAbs_FACE)
while face_explorer.More():
    face = topods.Face(face_explorer.Current())



    # 目标：内环线
    inner_wires=[]
    # 获取所有线
    wire_explorer = TopExp_Explorer(face, TopAbs_WIRE)
    # 获取外环wire线
    outer_wires = shapeanalysis_OuterWire(face)

    while wire_explorer.More():
        wire = topods.Wire(wire_explorer.Current())
        if not wire.IsSame(outer_wires):
            inner_wires.append(wire)
        wire_explorer.Next()

    display.DisplayShape(inner_wires, color=rgb_color(0,0,1))

    face_explorer.Next()

# display.DisplayShape(part)

# 显示3D视图
start_display()